import React from 'react';
import { Button, Tag, Tooltip, Space } from 'antd';

// 常量定义
export const typeOptions = ["防御型", "攻击型"];
export const statusOptions = ["代理处理中", "受让", "已受理", "原始取得", "暂无状态"];
export const departmentOptions = ["智能硬件部", "能源系统部", "研发部", "知识产权部"];

/**
 * 生成软著管理表格的列配置
 * @param {Object} handlers - 包含表格操作的处理函数
 * @returns {Array} 列配置数组
 */
export const getColumns = ({ onEdit, onDelete }) => [
  {
    title: "序号",
    dataIndex: "id",
    key: "id",
    width: 80,
    fixed: "left",
    sorter: (a, b) => a.id - b.id,
    defaultSortOrder: "ascend",
    ellipsis: true,
  },
  {
    title: "我司案号",
    dataIndex: "case_number",
    key: "case_number",
    width: 120,
    fixed: "left",
    ellipsis: true,
  },
  {
    title: "软件名称",
    dataIndex: "software_name",
    key: "software_name",
    width: 200,
    fixed: "left",
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "登记号",
    dataIndex: "registration_number",
    key: "registration_number",
    width: 150,
    ellipsis: true,
  },
  {
    title: "发明人",
    dataIndex: "inventors",
    key: "inventors",
    width: 150,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "技术交底书收集时间",
    dataIndex: "disclosure_time",
    key: "disclosure_time",
    width: 150,
    ellipsis: true,
  },
  {
    title: "开发完成日期",
    dataIndex: "development_complete_date",
    key: "development_complete_date",
    width: 150,
    ellipsis: true,
  },
  {
    title: "受理时间",
    dataIndex: "acceptance_date",
    key: "acceptance_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "发证时间",
    dataIndex: "issue_date",
    key: "issue_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "关联产品",
    dataIndex: "related_product",
    key: "related_product",
    width: 150,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "关联立项/课题",
    dataIndex: "related_project",
    key: "related_project",
    width: 150,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "防御型/攻击型",
    dataIndex: "type",
    key: "type",
    width: 120,
    filters: typeOptions.map((type) => ({ text: type, value: type })),
    onFilter: (value, record) => record.type === value,
    ellipsis: true,
  },
  {
    title: "首次发表日期",
    dataIndex: "first_publication_date",
    key: "first_publication_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "著作权人",
    dataIndex: "copyright_holder",
    key: "copyright_holder",
    width: 150,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "状态",
    dataIndex: "status",
    key: "status",
    width: 120,
    filters: statusOptions.map((status) => ({ text: status, value: status })),
    onFilter: (value, record) => record.status === value,
    render: (text) => {
      let color = "blue";
      if (text === "代理处理中") {
        color = "processing";
      } else if (text === "受让") {
        color = "warning";
      } else if (text === "已受理") {
        color = "success";
      } else if (text === "原始取得") {
        color = "green";
      }
      return text ? <Tag color={color}>{text}</Tag> : null;
    },
    ellipsis: true,
  },
  {
    title: "是否为核心",
    dataIndex: "is_core",
    key: "is_core",
    width: 100,
    render: (text) =>
      text ? <Tag color="green">是</Tag> : <Tag color="default">否</Tag>,
    filters: [
      { text: "是", value: true },
      { text: "否", value: false },
    ],
    onFilter: (value, record) => record.is_core === value,
    ellipsis: true,
  },
  {
    title: "核心分数",
    dataIndex: "core_score",
    key: "core_score",
    width: 100,
    sorter: (a, b) => a.core_score - b.core_score,
    ellipsis: true,
  },
  {
    title: "来源部门",
    dataIndex: "source_department",
    key: "source_department",
    width: 120,
    filters: departmentOptions.map((dept) => ({ text: dept, value: dept })),
    onFilter: (value, record) => record.source_department === value,
    ellipsis: true,
  },
  {
    title: "代理负责人",
    dataIndex: "agent_responsible",
    key: "agent_responsible",
    width: 120,
    ellipsis: true,
  },
  {
    title: "原名称",
    dataIndex: "original_name",
    key: "original_name",
    width: 180,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "特殊事项备注",
    dataIndex: "special_notes",
    key: "special_notes",
    width: 200,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "（发展部）关联课题/项目",
    dataIndex: "dev_related_project",
    key: "dev_related_project",
    width: 180,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "操作",
    key: "action",
    fixed: "right",
    width: 120,
    render: (_, record) => (
      <Space size="middle">
        <Button type="link" onClick={() => onEdit(record)}>
          编辑
        </Button>
        <Button type="link" danger onClick={() => onDelete(record)}>
          删除
        </Button>
      </Space>
    ),
  },
]; 